home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / datatypes / playdt13.lha / PlayDT / PlayDT-src / UseWB.c < prev   
C/C++ Source or Header  |  1997-06-05  |  4KB  |  189 lines

  1. /****************************************************************
  2.  *
  3.  * $VER: UseWB.c 1.3 (4.6.97) Tak Tang (tst92@ecs.soton.ac.uk)
  4.  *
  5.  * Copyright © 1997 Tak Tang
  6.  *
  7.  * You may use any part of this source code in your own programs
  8.  * provided that it is not called PlayDT.
  9.  *
  10.  ******************************************************************
  11.  *
  12.  */
  13.  
  14.  
  15. /**** Header files ****/
  16.  
  17. #include "PlayDT.h"
  18.  
  19. #include <workbench/startup.h>
  20.  
  21. #include <clib/dos_protos.h>
  22. #include <clib/exec_protos.h>
  23. #include <clib/datatypes_protos.h>
  24. #include <clib/intuition_protos.h>
  25.  
  26. #include <pragmas/dos_pragmas.h>
  27. #include <pragmas/exec_pragmas.h>
  28. #include <pragmas/datatypes_pragmas.h>
  29. #include <pragmas/intuition_pragmas.h>
  30.  
  31.  
  32. /****** UseWB ******************************************************
  33. *
  34. *   NAME
  35. *       UseWB - call PlayFile for each arg passed by wb, or call asl
  36. *
  37. *   SYNOPSIS
  38. *       UseWB ( GlobalData , WBArgArray )
  39. *
  40. *       UseWB ( struct GlobalData * , struct WBStartup * );
  41. *
  42. *   FUNCTION
  43. *       UseWB will attempt to call PlayFile() for each file passed by
  44. *       the workbench.  If no files are passed, then UseWB will call
  45. *       UseAsl.
  46. *
  47. *   INPUTS
  48. *       GlobalData -
  49. *
  50. *       WBArgArray - a WBArg array passed by workbench
  51. *
  52. *   RESULT
  53. *
  54. *   EXAMPLE
  55. *
  56. *   NOTES
  57. *
  58. *   BUGS
  59. *
  60. *   SEE ALSO
  61. *       UseCli.c/UseCli(), UseAsl.c/UseAsl()
  62. *
  63. *****************************************************************************
  64. *
  65. */
  66.  
  67.  
  68. void UseWB(struct GlobalData *gd, struct WBStartup *wbs)
  69. {
  70.   struct WBArg *wba;
  71.   ULONG i;
  72.   BPTR oldlock;
  73.  
  74.   gd->FromWB=TRUE;
  75.   if ( wbs->sm_NumArgs>1 )
  76.   {
  77.     wba=( wbs->sm_ArgList)+1;
  78.     for ( i= wbs->sm_NumArgs-1; i && FALSE==gd->UserStop; i--, wba++)
  79.     {
  80.       if (NULL!=wba->wa_Lock)
  81.       {
  82.         oldlock=CurrentDir( wba->wa_Lock );
  83.         if ( PlayFile(gd, wba->wa_Name) )
  84.         {
  85.           IntuiError( gd, wba->wa_Name );
  86.         } /* if error */
  87.         CurrentDir(oldlock);
  88.       } /* NULL != if wba_wa_Lock */
  89.     } /* for */
  90.   } /* if NumArgs>1 */
  91.   else
  92.   {
  93.     UseASL(gd);
  94.   } /* if NumArgs<2 */
  95. } /* UseWB */
  96.  
  97.  
  98. /****** IntuiError *************************************************
  99. *
  100. *   NAME
  101. *       IntuiError - display the ioerr message using easyrequest
  102. *
  103. *   SYNOPSIS
  104. *       IntuiError( GlobalData, FileName )
  105. *
  106. *       IntuiError( struct tGlobalData *, STRPTR );
  107. *
  108. *   FUNCTION
  109. *       This routine gets the ioerr using Fault(), and displays
  110. *       the message in a window using EasyRequest.  The requester
  111. *       offers the user two options- OK and ABORT.  Selecting ABORT
  112. *       will set the gd->UserStop flag.
  113. *       It will open intuition if it is not already open, but does
  114. *       not close it.
  115. *
  116. *   INPUTS
  117. *       GlobalData - A pointer to structure containing library bases
  118. *                        and other global data.
  119. *
  120. *       FileName   - The filename of the sound sample to play, relative
  121. *                        to the current directory.  This is not checked
  122. *                        to see if it is a valid filename.
  123. *
  124. *   RESULT
  125. *       (gd->UserStop)  - This flag is set if we could not open
  126. *                         intuition.library, or if the user selected
  127. *                         ABORT
  128. *
  129. *   EXAMPLE
  130. *
  131. *   NOTES
  132. *
  133. *   BUGS
  134. *
  135. *   SEE ALSO
  136. *
  137. *****************************************************************************
  138. *
  139. */
  140.  
  141.  
  142. void IntuiError(struct GlobalData *gd, STRPTR filename)
  143. {
  144.   LONG rc;
  145.   UBYTE buffer[81];
  146.   struct EasyStruct ez = {
  147.     sizeof(struct EasyStruct), 0, "PlayDT 1.3",
  148.     "%s: %s","OK|ABORT"};
  149.  
  150.   /* open Intuition library if necessary */
  151.   if ( NULL == gd->IntuitionBase ) {
  152.     if (gd->IntuitionBase = OpenLibrary ("intuition.library", 39L))
  153.     {
  154.       IntuitionBase=gd->IntuitionBase;
  155.     }
  156.   }
  157.  
  158.   if ( gd->IntuitionBase ) {
  159.     /* Generate the message */
  160.     rc=IoErr();
  161.     if (rc >= DTERROR_UNKNOWN_DATATYPE)
  162.     {
  163.       if ( 0==EasyRequest(NULL, &ez, NULL, filename, GetDTString (rc)) )
  164.       {
  165.         gd->UserStop=TRUE;
  166.       } /* if 0==choice */
  167.     }
  168.     else
  169.     {
  170.       if ( Fault( IoErr(), NULL, buffer, 81) )
  171.       {
  172.         if ( 0==EasyRequest(NULL, &ez, NULL, filename, buffer) )
  173.         {
  174.           gd->UserStop=TRUE;
  175.         } /* if 0==choice */
  176.       } /* if fault() */
  177.     }
  178.   } /* if intuitionbase */
  179.   else
  180.   {
  181.     /* MUST abort now */
  182.     gd->UserStop=TRUE;
  183.   } /* If cant open intuition */
  184. } /* IntuiError */
  185.  
  186.  
  187. /**** End of file ****/
  188.  
  189.